
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.by import By


# service = Service('C:\pydd\pythonProject\chromedriver.exe')
#
# browser = webdriver.Chrome(service=service)

from have import *


browser = browser_have()

# url
url = 'https://www.baidu.com'

# 打开
browser.get(url=url)

import time

time.sleep(2)
print(1)

# 获取文本框对象
input = browser.find_element(By.ID, 'kw')

# 在文本框中输入 需要搜索的内容
input.send_keys('安悦溪')

time.sleep(2)
print(2)


# 获取百度一下按钮
button = browser.find_element(By.ID, 'su')

# 点击按钮
button.click()

time.sleep(2)
print(3)


# 滑到底部
js_bottom = 'document.documentElement.scrollTop=100000'
browser.execute_script(js_bottom)
time.sleep(5)
print(4)

# 下一页的按钮
next = browser.find_element(By.XPATH, '//a[@class="n"]')

# 点击下一页
next.click()
time.sleep(5)

# 回到上一页
browser.back()

time.sleep(3)

# 返回下一页
browser.forward()

time.sleep(3)

# 退出
browser.quit()
